//
//  STCollectionViewController.m
//  STNewTools
//
//  Created by stoneobs on 2017/7/31.
//  Copyright © 2017年 stoneobs. All rights reserved.
//

#import "STCollectionViewController.h"
#import "STCalendarKitItemCollectionViewCell.h"
#import "UIView+STDirection.h"
#import "STCollectionLayout.h"
@interface STCollectionViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView            *collectionView;
@property(nonatomic,strong)NSMutableArray<NSMutableArray*>            *dataSouce;

@end

@implementation STCollectionViewController

- (UICollectionView *)collectionView{
    
    if (!_collectionView) {
        
        STCollectionLayout * flow = [STCollectionLayout new];
        [flow setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        flow.minimumLineSpacing = 0;
        flow.minimumInteritemSpacing = 0;
        flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 100, self.view.width, itemWith * 6 ) collectionViewLayout:flow];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.pagingEnabled = YES;
        _collectionView.showsHorizontalScrollIndicator = NO;
        [_collectionView registerClass:[STCalendarKitItemCollectionViewCell class]
            forCellWithReuseIdentifier:@"test"];
        
    }
    return _collectionView;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.dataSouce = [NSMutableArray new];
    for (int k = 0; k < 5; k++) {
        NSMutableArray * sectionArray = [NSMutableArray new];
        for (int i = 0; i<42; i++) {
            STCalendarKitDayModel * model = [STCalendarKitDayModel new];
            model.dayValue = i;
            [sectionArray addObject:model];
        }
        [self.dataSouce addObject:sectionArray];
    }

    [self.view addSubview:self.collectionView];
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma --mark UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.dataSouce.count;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataSouce[section].count;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(itemWith, itemWith);
}
- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    __weak typeof(self) weakSelf = self;
    STCalendarKitItemCollectionViewCell * item = [collectionView dequeueReusableCellWithReuseIdentifier:@"test" forIndexPath:indexPath];
    item.model = self.dataSouce[indexPath.section][indexPath.item];
    [item setButtonAction:^(UIButton * button){
       NSLog(@"section %ld   item:%ld",(long)indexPath.section,(long)indexPath.row);
    }];
    return item;
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
  
   
}
#pragma --mark UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
   
    [self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
}



@end
